package com.masterclient.app.modules.order;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.eoner.baselibrary.bean.address.AddressMessage;
import com.masterclient.app.R;

public class PickGoodsAddressDialog extends Dialog implements View.OnClickListener {

    private String num;
    private AddressMessage addressMessage;

    public PickGoodsAddressDialog(@NonNull Context context, String num, AddressMessage addressMessage, OnConfirmListener onConfirmListener) {
        super(context, R.style.MyDialog);
        this.num = num;
        this.addressMessage = addressMessage;
        this.onConfirmListener = onConfirmListener;
    }

    private ImageView ivClose;
    private TextView tvNum, tvName, tvPhone, tvInfo, tvConfirm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_pick_goods_address);

        ivClose = findViewById(R.id.dialog_pick_goods_address_close);
        tvNum = findViewById(R.id.dialog_pick_goods_address_num);
        tvName = findViewById(R.id.dialog_pick_goods_address_name);
        tvPhone = findViewById(R.id.dialog_pick_goods_address_phone);
        tvInfo = findViewById(R.id.dialog_pick_goods_address_detail);
        tvConfirm = findViewById(R.id.dialog_pick_goods_address_confirm);
        ivClose.setOnClickListener(this);
        tvConfirm.setOnClickListener(this);

        tvNum.setText(num);
        tvName.setText(addressMessage.getFull_name());
        tvPhone.setText(addressMessage.getMobile());
        tvInfo.setText(new StringBuffer(addressMessage.getProvince()).append(addressMessage.getCity()).append(addressMessage.getArea()).append(addressMessage.getAddress()));
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.dialog_pick_goods_address_close:
                dismiss();
                break;
            case R.id.dialog_pick_goods_address_confirm:
                onConfirmListener.onConfirm();
                dismiss();
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        windowparams.height = WindowManager.LayoutParams.MATCH_PARENT;
        windowparams.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    private OnConfirmListener onConfirmListener;

    public interface OnConfirmListener{
        void onConfirm();
    }

}
